var models = require('../models');
var Saaser = models.Saaser;


exports.getAllClass = function (callback) {
    Saaser.find({'nodetype': '类别'}, callback);
};

exports.getClass = function (cl, callback) {
    Saaser.findOne({'title': cl}, callback);
};

exports.pushGroup = function (cls, group, callback) {
    Saaser.findOne({'title': cls}, function (err, cl) {
        if (err) {
            return callback(err);
        }
        console.log(cl);
        var saaser = new Saaser();
        saaser.title = group;
        saaser.nodetype = '组别';
        cl.childs.push(saaser);

        console.log(cl);
        cl.save(callback);
    });
};

exports.pushItem = function (cls, group, item, callback) {
    Saaser.findOne({'title':cls}, function (err,cl) {
        if (err) {
            return callback(err);
        }

    });
};

exports.newAndSave = function (pid, title, url, thumb, sort, nodetype, callback) {
    var saaser = new Saaser();
    saaser.title = title;
    saaser.url = url;
    saaser.thumb = thumb;
    saaser.sort = sort;
    saaser.nodetype = nodetype;
    saaser.save(callback);
};